package org.aeon.client.view.components.sessionPanel.confirmDialog;

import org.aeon.client.context.GlobalContext;
import org.aeon.client.view.ApplicationUI;
import org.aeon.utils.SwingUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

/**
 * @author: MissingAeon
 * @date: 2024/3/11 16:14
 * @description:
 */
public class ExitGroupConfirmDialog extends JPanel {
    private final JButton closeBut;
    private final JButton submit;
    private final JButton cancel;

    public ExitGroupConfirmDialog() {
        SwingUtil.setSize(this, new Dimension(350, 180));
        final ApplicationUI mainUI = GlobalContext.getContext().getMainUI();
        this.setBounds((mainUI.getWidth() - 350) / 2, (mainUI.getHeight() - 180) / 2, 350, 180);
        this.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.GRAY));

        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        this.add(Box.createVerticalStrut(5));
        // ×
        final Box closeBox = Box.createHorizontalBox();
        closeBut = new JButton("×");
        closeBut.setFont(new Font("黑体", Font.PLAIN, 16));
        closeBut.setMargin(new Insets(0, 0, 0, 0));
        SwingUtil.removeStyle(closeBut);
        SwingUtil.setSize(closeBut, new Dimension(25, 25));
        closeBox.add(Box.createHorizontalGlue());
        closeBox.add(closeBut);
        closeBox.add(Box.createHorizontalStrut(5));

        this.add(closeBox);

        this.add(Box.createVerticalStrut(5));

        // 提示
        final Box promptBox = Box.createHorizontalBox();
        promptBox.add(Box.createHorizontalStrut(20));
        final JLabel promptLabel = new JLabel("确认退出群聊吗");
        promptLabel.setFont(new Font("黑体", Font.PLAIN, 16));
        promptBox.add(promptLabel);
        promptBox.add(Box.createHorizontalGlue());

        this.add(promptBox);
        // this.add(Box.createVerticalStrut(10));

        //  选项
        final Box blockBox = Box.createHorizontalBox();
        final JLabel blockBut = new JLabel("<html>退出后不会通知群聊中其他成员，且不会<br>再接收此群消息。</html>");
        blockBut.setFont(new Font("黑体", Font.PLAIN, 14));
        blockBox.add(Box.createHorizontalStrut(20));
        blockBox.add(blockBut);
        blockBox.add(Box.createHorizontalGlue());

        this.add(blockBox);
        this.add(Box.createVerticalStrut(10));

        final Box operationBox = Box.createHorizontalBox();
        submit = new JButton("确认");
        SwingUtil.removeStyle2(submit);
        cancel = new JButton("取消");
        SwingUtil.removeStyle2(cancel);
        operationBox.add(Box.createHorizontalGlue());
        operationBox.add(submit);
        operationBox.add(Box.createHorizontalStrut(10));
        operationBox.add(cancel);
        operationBox.add(Box.createHorizontalStrut(20));

        this.add(operationBox);
        this.add(Box.createVerticalGlue());

    }

    /**
     * 添加提交事件
     *
     * @param listener
     */
    public void submit(ActionListener listener) {
        submit.addActionListener(listener);
    }

    /**
     * 添加取消事件
     *
     * @param listener
     */
    public void cancel(ActionListener listener) {
        closeBut.addActionListener(listener);
        cancel.addActionListener(listener);
    }
}
